<?php

class myUser extends sfGuardSecurityUser
{
 public function resetDownloadHistory()
  {
    $this->getAttributeHolder()->remove('download_history');
  }
	
public function getDownloadHistory()
  {
    $ids = $this->getAttribute('download_history', array());
 
    if (!empty($ids))
    {
      return Doctrine_Core::getTable('Fily')
        ->createQuery('a')
        ->whereIn('a.id', $ids)
        ->execute()
      ;
    }
 
    return array();
  }
  
public function addDownloadToHistory(Fily $fily)
  {
  
  
    $ids = $this->getAttribute('download_history', array());
 
    if (!in_array($fily->getId(), $ids))
    {
      array_unshift($ids, $fily->getId());
 
      $this->setAttribute('download_history', array_slice($ids, 0, 3));
    }
  }
}
